package com.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.sfzy.entity.ConsultantTag;
import com.sfzy.service.ConsultantTagService;
import com.sfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("consultantTag")
public class ConsultantTagController {
    @Autowired
    private ConsultantTagService consultantTagService;
    //增加
    @PostMapping("add")
    public R insertConsultantTag(ConsultantTag consultantTag) {
        int num = consultantTagService.insertConsultantTag(consultantTag);
        if (num > 0) {
            return R.ok();
        }else{
            return R.fail();
        }
    }
    //删除
    @DeleteMapping("{id}")
    public R deleteConsultantTag(@PathVariable("id") int id) {
        int num = consultantTagService.deleteConsultantTag(id);
        if (num > 0) {
            return R.ok();
        }else{
            return R.fail();
        }
    }
    //修改
    @PutMapping("update")
    public R updateConsultantTag(ConsultantTag consultantTag) {
        int num = consultantTagService.updateConsultantTag(consultantTag);
        if (num > 0) {
            return R.ok();
        }else{
            return R.fail();
        }
    }
    //根据id查询
    @GetMapping("{id}")
    public R getConsultantTagById(@PathVariable("id") int id) {
        ConsultantTag consultantTag = consultantTagService.selectConsultantTagById(id);
        return R.ok(consultantTag);
    }
    //分页查询
    @GetMapping("page")
    public R getConsultantTags(ConsultantTag consultantTag,
                               @RequestParam(required = false,defaultValue = "1")int pageNum,
                               @RequestParam(required = false,defaultValue = "3")int pageSize){
        PageInfo<ConsultantTag> consultantTagPageInfo = consultantTagService.selectAllConsultantTags(consultantTag, pageNum, pageSize);
        return R.ok(consultantTagPageInfo);
    }
}
